package com.fms.kccc.controller;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fms.kccc.object.ImageContent;
import com.fms.kccc.service.ImageContentService;
import com.fms.kccc.service.ImageContentServiceImpl;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.blobstore.UploadOptions;
import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.files.AppEngineFile;
import com.google.appengine.api.files.FileService;
import com.google.appengine.api.files.FileServiceFactory;
import com.google.appengine.api.files.FileWriteChannel;

public class MarkedImageContentServlet extends BaseServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String PARAMETER_CATEGORY = "category";
	private static final String PARAMETER_PAGE = "page";
	private static final String PARAMETER_ROWS = "rows";
	private static final String PARAMETER_DATE = "date";

	ImageContentService imageContentService = new ImageContentServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		int page = Integer.parseInt(getParameter(req, PARAMETER_PAGE));
		int rows = Integer.parseInt(getParameter(req, PARAMETER_ROWS));
		long dateValue = Long.parseLong(getParameter(req, PARAMETER_DATE));
		Date date = new Date(dateValue);
		String category = getParameter(req, PARAMETER_CATEGORY);
		List<ImageContent> imageContents = imageContentService
				.getMarkedImageContents(category, date, page, rows);
		jsonRespone(resp, HttpServletResponse.SC_OK,
				ImageContent.toJsonArray(imageContents));
	}
}
